package com.chj.design.sk;

import java.util.ArrayList;
import java.util.List;

public class Code17_Builder {

	public interface Food {
		public String getName();
	}

	public static class Bread implements Food {
		@Override
		public String getName() {
			return "面包";
		}
	}

	public static class Vegetables implements Food {
		@Override
		public String getName() {
			return "蔬菜";
		}
	}

	public static class Chicken implements Food {
		@Override
		public String getName() {
			return "鸡肉";
		}
	}

	public static abstract class Hamburger {
		private List<Food> part = new ArrayList<>();

		public void addFood(Food food) {
			part.add(food);
		}

		public void showFood() {
			System.out.println("汉堡组成：");
			for (Food food : part) {
				System.out.print(food.getName() + "\t");
			}
			System.out.println("");
		}
	}

	public static class BigHamburger extends Hamburger {
	}

	public static class SmallHamburger extends Hamburger {
	}

	public static abstract class Builder {
		public abstract void addFood();

		public abstract Hamburger makeHamburger();
	}

	public static class BigHamburgerBuilder extends Builder {
		private BigHamburger bigHamburger = new BigHamburger();

		@Override
		public void addFood() {
			bigHamburger.addFood(new Bread());
			bigHamburger.addFood(new Vegetables());
			bigHamburger.addFood(new Chicken());
			bigHamburger.addFood(new Vegetables());
			bigHamburger.addFood(new Chicken());
			bigHamburger.addFood(new Bread());
		}

		@Override
		public Hamburger makeHamburger() {
			return bigHamburger;
		}
	}

	public static class SmallHamburgerBuilder extends Builder {
		private SmallHamburger smallHamburger = new SmallHamburger();

		@Override
		public void addFood() {
			smallHamburger.addFood(new Bread());
			smallHamburger.addFood(new Vegetables());
			smallHamburger.addFood(new Chicken());
			smallHamburger.addFood(new Bread());
		}

		@Override
		public Hamburger makeHamburger() {
			return smallHamburger;
		}
	}

	public static class Director {
		private Builder bigHamburgerBuilder = new BigHamburgerBuilder();
		private Builder smallHamburgerBuilder = new SmallHamburgerBuilder();

		public Hamburger makeBigHamburger() {
			bigHamburgerBuilder.addFood();
			return bigHamburgerBuilder.makeHamburger();
		}

		public Hamburger makeSmallHamburger() {
			smallHamburgerBuilder.addFood();
			return smallHamburgerBuilder.makeHamburger();
		}
	}

	public static void main(String[] args) {
		Director director = new Director();
		Hamburger bigHamburger = director.makeBigHamburger();
		Hamburger samllHamburger = director.makeSmallHamburger();
		bigHamburger.showFood();
		samllHamburger.showFood();
	}

}
